<?php
class JobSvn extends Job implements IJob
{
  protected $repository = null;
  
  public function doBackup()
  {
    $h = "";
    if($this->host!=null)
    {
      $h = " http://" . $this->host . "/";
    }
    $r = "";
    if($this->repository!=null)
    {
      $r = $this->repository;
    }
    $u = "";
    if($this->user!=null)
    {
      $u = " --username " . $this->user;
    }
    $p = "";
    if($this->password!=null)
    {
      $p = " --password=" . $this->password;
    }
    
    if(!is_dir(dirname($this->getDestinationBackup())))
    {
      mkdir(dirname($this->getDestinationBackup()), 0660, true);
    }
    
    $cmds   = array();
    $cmds[] = "svn export --non-interactive --force" . $u . $p . $h . $r . " " . $this->getDestinationBackup();
    
    $this->execCommandos($cmds);
  }
  
  public function getFileExtensionBackup()
  {
    return "";
  }
  
  public function getFileExtensionCompression()
  {
    return ".tar.gz";
  }
    
  public function getFileIdentifier()
  {
    return $this->repository;
  }
  
  public function postLoadJob()
  {
    return;
  }  
  
  public function setRepository($repository)
  {
    $this->repository = $repository;
  }
  
  public function setOptions($optionsElement)
  {
    foreach($optionsElement->children() as $optionElement)
    {
      switch($optionElement->getName())
      {
        case "Repository":
          $this->setRepository((string)$optionElement);
          break;
                        
        default:
          $this->logger->warn("Unknown option element '" . $optionElement->getName() . "'.");
          break;
      }
    }    
  }
}